﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using HA.ModFlow.Domain.FileLayer;

using HA.ModFlow.Infrastructure;



namespace HA.ModFlow.Domain.DomainLayer
{


    /// <summary>
    /// 作为可能的第二版设计的流动包部分,为了减少内存的使用，以及数据的操作幅度
    /// </summary>
    [Serializable]
    public class InnerFlowV2 : ICloneable
    {

        public InnerFlowV2(GridData gridData)
        {


            this._gridData = gridData;


            //初始化对应的数据

            this.InitGridData();


            this._bcfData = new BCFData(this);

            this._lpfData = new LPFData(this);






        }






        GridData _gridData;

        public GridData GridData
        {
            get { return _gridData; }
            set { _gridData = value; }
        }




        BCFData _bcfData;

        public BCFData BcfData
        {
            get { return _bcfData; }

        }


        LPFData _lpfData;

        public LPFData LpfData
        {
            get { return _lpfData; }

        }






        //公共属性区

        CellCenterDataSet3d _hk;

        /// <summary>
        /// 水平传导系数，
        /// /// <summary>
        /// BCF时 当层类型为1或者3时，需要此数据，行的水力传导系数。HY乘以TRPY等于列的水力传导系数，非承压状态 或者可转状态 渗透系数是变量时
        /// </summary>
        /// </summary>
        public CellCenterDataSet3d Hk
        {
            get { return _hk; }
            set { _hk = value; }
        }



        CellCenterDataSet3d _wetDry;

        /// <summary>
        /// 干湿标志的数组，和Canwet标志相关
        /// </summary>
        public CellCenterDataSet3d WetDry
        {
            get { return _wetDry; }
            set { _wetDry = value; }
        }





        bool _canWet = false;


        /// <summary>
        /// 是否启用湿化功能 
        /// </summary>
        public bool CanWet
        {
            get { return _canWet; }
            set { _canWet = value; }
        }




        double _HDRY = -888.0;

        /// <summary>
        /// 干单元的水头值
        /// </summary>
        public double HDRY
        {
            get { return _HDRY; }
            set { _HDRY = value; }
        }



        double _WETFCT = 1.0;

        /// <summary>
        /// 湿化因子
        /// </summary>
        public double WETFCT
        {
            get { return _WETFCT; }
            set { _WETFCT = value; }
        }

        int _IWETIT = 1;


        /// <summary>
        /// 尝试润湿单元的迭代间隔
        /// </summary>
        public int IWETIT
        {
            get { return _IWETIT; }
            set { _IWETIT = value; }
        }


        int _IHDWET = 0;

        /// <summary>
        /// 
        /// 湿化单元的初始水头计算公式
        /// </summary>
        public int IHDWET
        {
            get { return _IHDWET; }
            set { _IHDWET = value; }
        }


        bool _IsHaveTransient = true;
        /// <summary>
        /// 
        /// 是否含有瞬时非稳定流模型
        /// </summary>

        public bool IsHaveTransient
        {
            get { return _IsHaveTransient; }
            set
            {
                _IsHaveTransient = value;
                this._lpfData.OnLPFDataChanged();
                this._bcfData.OnBCFDataChanged();
            }
        }

        public object Clone()
        {
            return this.MemberwiseClone();
        }





        #region 对外的公用函数

        public void OnResetGrid(GridData gd)
        {

            this._gridData = gd;

            this.InitGridData();




        }




        public void OnSetHaveStressPeriod(bool isHave)
        {
            this.IsHaveTransient = isHave;
        }

        public void OnIboundsChanged(List<int[,]> iBound)
        {
            if (this._hk != null)
                this._hk.SetIBounds(iBound);
            if (_wetDry != null)
                this._wetDry.SetIBounds(iBound);
            if (_bcfData != null)
                this._bcfData.OnIboundsChanged(iBound);
            if (_lpfData != null)
                this._lpfData.OnIboundsChanged(iBound);
        }

        #endregion


        #region 内部方法

        protected void InitGridData()
        {


            //这里先只开始一个作为测试用

            double[, ,] hk = new double[this._gridData.RowsCount, this._gridData.ColsCount, this._gridData.LayersCount];


            this._hk = new CellCenterDataSet3d(hk, this._gridData.WaterGrid.GetIBounds());

            this._hk.Label = "HK";


            double[, ,] wetDry = new double[this._gridData.RowsCount, this._gridData.ColsCount, this._gridData.LayersCount];
            this.WetDry = new CellCenterDataSet3d(wetDry, this._gridData.WaterGrid.GetIBounds());
            this.WetDry.Label = "WetDry";

            this.WetDry.ConstantData(1);


        }

        #endregion



    }
}
